// pages/index/index.js
import Toast from '@vant/weapp/toast/toast';
import {request} from '../../utils/request.js'

Page({
  onShow(){
    this.findAllUnits()
  },
  data: {
    array:[],
    childrenindex:1
  },
  findAllUnits(){//学校信息
    let vm = this
    request({
      url:'/review-paper/system/organization/findAllUnits',
      data:{},
      success (res) {
        if(res.data.status == 1){
            wx.setStorage({
              key:"schoolInfo",
              data:res.data.data[0]
            })
            vm.getReviewTask(res.data.data[0])
        }else{
          Toast.fail(res.data.msg);
        }
      }
    })
  },
  getReviewTask(data){//阅卷信息
    let vm = this
    request({
      url:'/review-paper/exam/getReviewTask',
      data:{
        schoolId:data.id
      },
      success (res) {
        if(res.data.status == 1){
          if(res.data.data && res.data.data.length > 0){
            res.data.data.forEach(val => {
              val.reviewTaskVoList.forEach(va => {
                va.examId = val.examId
              })
            })
          }
          vm.setData({
            array: res.data.data
          })
        }else{
          Toast.fail(res.data.msg);
        }
      }
    })
    
  },
  //跳转阅卷
  toMark(e){
    //传递科目信息
    wx.setStorage({
      key:'gradingPaperDetail',
      data:e.target.dataset.data
    })
    //传递考试信息
    let dat = {}
    this.data.array.forEach(val => {
      if(val.examId == e.target.dataset.data.examId){
        dat = val
      }
    })
    wx.setStorage({
      key:'gradingPaper',
      data:dat
    })
    wx.navigateTo({
      url: '../markingPapers/markingPapers?id=1'
    })
  },
  //跳转视频号
  navigateToChannel: function() {
    wx.openChannelsUserProfile({
      finderUserName:getApp().globalData.sphId,
      complete(e){
        console.log(e)
      }
    })
  }
})
